import { WebSocketGateway, SubscribeMessage, MessageBody, WebSocketServer } from '@nestjs/websockets';
import { Server } from 'socket.io';
import { ChatgptService } from './chatgpt.service';
import { CreateChatgptDto } from './dto/create-chatgpt.dto';
import { UpdateChatgptDto } from './dto/update-chatgpt.dto';

@WebSocketGateway({
  cors: {
    origin: '*',
},
})
export class ChatgptGateway {
  @WebSocketServer()
  server: Server;

  constructor(private readonly chatgptService: ChatgptService) {}
  //接受前端发送的chat消息
  @SubscribeMessage('chat')
  async handleChat(@MessageBody() createChatgptDto: CreateChatgptDto) {
    return this.chatgptService.handleChat(this.server, createChatgptDto);
  }

  @SubscribeMessage('stopGeneration')
  create(@MessageBody() conversationId) {
    return this.chatgptService.stopGeneration(this.server,conversationId.conversationId);
  }

}
